<template>
  <op-date
    v-model="newValue"
    type="daterange"
    unlink-panels
    range-separator="To"
    start-placeholder="Start date"
    end-placeholder="End date"
    :initDate="initDate[initDateType]"
    @itemEvent="itemEvent"
  />
</template>

<script setup>
import moment from 'moment';
import { vModelValue } from '@/utils/hooks.js';

/* 
  1:往前推一年
  2:往前推三个月
*/
const initDate = {
  1: [moment().subtract(1, 'year').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')],
  2: [moment().subtract(3, 'months').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')],
};

const emit = defineEmits(['update:modelValue', 'itemEvent']);

const props = defineProps({
  modelValue: {
    type: [String, Array],
    default: '',
  },
  initDateType: {
    type: String,
    default: '1',
  },
});
const { newValue } = vModelValue(props, emit);

function itemEvent(obj) {
  emit('itemEvent', obj);
}
</script>
